package sim.ring.gui.actions;

import org.eclipse.jface.action.Action;
import org.eclipse.jface.dialogs.InputDialog;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.widgets.Display;

import sim.ring.gui.RingingSimApp;
import sim.ring.gui.RingingSimManager;
import sim.ring.gui.treedata.MethodTreeContentProvider;

public class AddNewFolderAction extends Action {

	RingingSimApp r;
	
	private static String _DIALOGTITLE, _DIALOGPROMPT;
	
	public AddNewFolderAction(RingingSimApp parent) {
		r = parent;
		setText(r.getLocalisedData("newFolderAction", "&New folder@Ctrl+N"));
		setToolTipText(r.getLocalisedData("newFolderActionTooltip", "Create a new folder"));
		setImageDescriptor(RingingSimManager.getIMGReg().getDescriptor("newFolder"));
		_DIALOGPROMPT = r.getLocalisedData("newFolderDialogPrompt", "Specify folder name");
		_DIALOGTITLE = r.getLocalisedData("newFolderDialogTitle", "Create a new folder");
	}
	
	@Override
	public void run() {
		InputDialog dlg = new InputDialog(
				Display.getCurrent().getActiveShell(),
				_DIALOGTITLE, _DIALOGPROMPT,
				"", null);
		if (dlg.open() == Window.OK) {
			((MethodTreeContentProvider)r.getTV().getContentProvider()).addNewFolder(dlg.getValue());
		}
	}


}
